import { Select, SelectProps } from 'antd'
import { useMemo } from 'react'
import { KeyLabelEnum } from '@/types'
import { EnumUtil } from '@/utils'

/**
 * 枚举下拉框属性
 */
interface EnumSelectProps extends SelectProps {
  /** 枚举定义 */
  enumDef: KeyLabelEnum
}

/**
 * 枚举下拉框
 */
export const EnumSelect = ({ enumDef, ...props }: EnumSelectProps) => {
  const options = useMemo(() => {
    return EnumUtil.getEnumOption(enumDef)
  }, [enumDef])
  return <Select {...props} options={options} />
}
